<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 16-8-25
 * Time: 下午4:35
 */
namespace Company\Controller;

use Think\Controller;

class GoodsTypeController extends Controller{
    
    /**
     * 产品分类
     */
    public function getGoods()
    {
        //  获取数据库产品信息
        $goodsType=D("product_type");
        $list=$goodsType->select();
        $this->assign("list",$list);
        $this->display();
    }

    public function addGoods(){
        //添加产品
        $name=$_POST["name"];
        $d=D("product_type");
        $data["name"]=$name;
        $data["sid"]=1;
        $re=$d->add($data);
        if(!empty($re)){
            $this->success('添加成功','getGoods');
        }
        else{
            $this->error('添加失败','getGoods');
        }

    }

    public function upGoods(){
        //根据id获取表单数据库信息
        $id=$_GET["id"];
        $d=D("product_type");
        $list=$d->where("id='$id'")->select();
        $this->assign("list",$list);
        $this->display();

    }

    public function  edGoods(){
        //  跟新产品数据库操作
        $id=$_POST["id"];
        $name=$_POST["name"];
        $d=D("product_type");
        $data["name"]=$name;
        $data["sid"]=1;
        $re=$d->where("id='$id'")->save($data);
        if(!empty($re)){
            $this->success('更改成功','getGoods');
        }
        else{
            $this->error('更改失败','getGoods');
        }
    }

    public function delete(){
        //  删除产品类操作
        $id=$_GET["id"];
        $delete=D("product_type");
        $de = $delete->delete($id);
        if(!empty($de)){
            $this->success('删除成功','getGoods');
        }
        else{
            $this->error('删除失败','getGoods');
        }

    }
    
    
}